package com.fund.com.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fund.com.config.GlobalExceptionHandler;
import com.fund.com.dao.TFollowDao;
import com.fund.com.entity.TFollow;
import com.fund.com.service.TFollowService;
import com.fund.utils.PageUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * (TFollow)表服务实现类
 *
 * @author makejava
 * @since 2023-02-15 19:42:46
 */
@Service("tFollowService")
public class TFollowServiceImpl extends ServiceImpl<TFollowDao, TFollow> implements TFollowService {

    @Override
    public Page<TFollow> getPage(Page<TFollow> page, TFollow tFollow) {
        Page<TFollow> pageVo = new Page<>(page.getCurrent(), page.getSize() == 0L ? PageUtil.SIZE : page.getSize(), this.count());
        return this.page(pageVo, new QueryWrapper<TFollow>(tFollow));
    }

    /**
     * 根据名称模糊分页查询，待填入名称
     */
    @Override
    public Page<TFollow> getPageLikeName(Page<TFollow> page, TFollow tFollow) {
        Page<TFollow> pageVo = new Page<>(page.getCurrent(), page.getSize() == 0L ? PageUtil.SIZE : page.getSize(), this.count());
        return this.page(pageVo, new QueryWrapper<TFollow>().like(StringUtils.isNotBlank(""), "", tFollow));
    }

    @Override
    public Boolean insertOne(TFollow tFollow) {
        boolean save = this.save(tFollow);
        if (!save) {
            throw new GlobalExceptionHandler("保存失败");
        }
        return true;
    }

    @Override
    public Boolean updateOneById(TFollow tFollow) {
        boolean b = this.updateById(tFollow);
        if (!b) {
            throw new GlobalExceptionHandler("更新失败");
        }
        return true;
    }

    @Override
    public Boolean deleteListByIds(List<String> idList) {
        List<Long> collect = idList.stream().map(f -> Long.parseLong(f)).collect(Collectors.toList());
        boolean b = this.removeByIds(collect);
        if (!b) {
            throw new GlobalExceptionHandler("删除失败");
        }
        return true;
    }

    @Override
    public TFollow getOneById(String id) {
        return this.getById(Long.parseLong(id));
    }

    @Override
    public List<TFollow> queryAll(TFollow tFollow) {
        return this.list(new QueryWrapper<TFollow>(tFollow));
    }
}

